#include "base_globals.h"
#include <string.h>

Globals* globals()
{
    static Globals globals;
    return &globals;
}

EBaseError globals_init()
{
    EBaseError ret = BASE_SUCCEED;
    Globals* g = globals();
    memset(&g->log,0,sizeof(BaseLog));
    g->log.path = "log.txt";
    g->conf.log_level = LOG_DEBUG;
    
    ret = log_init(&g->log);
    if (ret != BASE_SUCCEED) {
        return ret;
    }
    DEBUG("DEBUG: Log system initialized");
    return BASE_SUCCEED;
}

void globals_fini()
{
    Globals* g = globals();
    log_fini(&g->log);
    memset(&g->log,0,sizeof(BaseLog));
}

void globals_change_log_level(EBaseLogLevel level)
{
    Globals* g = globals();
    g->conf.log_level = level;
}